<?php namespace Phpcmf\Controllers;

class Miyue extends \Phpcmf\Common {

    private $token;
    private $access_token;

    public function index() {
        \Phpcmf\Service::C()->init_file('weixin');
        $signPackage=\Phpcmf\Service::L('jssdk','weixin')->GetSignPackage();
        $this->_json(1, 1, $signPackage);
    }
    public function zhifu() {
        \Phpcmf\Service::C()->init_file('weixin');
        $signPackage=\Phpcmf\Service::L('jssdk','weixin')->GetSignPackage();
        $this->_json(1, 1, $signPackage);
    }
    public function tuwen() {
        $tid = \Phpcmf\Service::L('Input')->get('id');
        if(!$tid){
            $this->_json(0, 0, 'ID数据错误');
        }
        $duoquans = \Phpcmf\Service::M()->db->table('1_quan_shezhi')->where('dirname', 'quan')->get()->getRowArray();
        $duoquan = dr_string2array($duoquans['setting']);
        $quanliulan = $duoquan['pages']['quan_liulan'];
        $quantupianlist = $duoquan['pages']['quan_tupian_list'];
        $qiniusuolietu = $duoquan['pages']['quan_qiniutuhouzhui'];
        $alisuolietu = $duoquan['pages']['quan_alituhouzhui'];
        $tengxunsuolietu = $duoquan['pages']['quan_tengxuntuhouzhui'];
        if($quantupianlist == 1){
            $houzhuitu = '';
        }elseif($quantupianlist == 2){
            $houzhuitu = $qiniusuolietu;
        }elseif($quantupianlist == 3){
            $houzhuitu = $alisuolietu;
        }elseif($quantupianlist == 4){
            $houzhuitu = $tengxunsuolietu;
        }

        
        $tiedata = \Phpcmf\Service::M()->db->table('1_quan_form_son')->where('id', $tid)->get()->getRowArray();
        if($tiedata['title']){
            $title = $tiedata['title'];
        } else {
            $title = dr_strcut(dr_clearhtml($tiedata['neirong']), 10);
        }
        $jianjie = dr_strcut(dr_clearhtml($tiedata['neirong']), 20);
        $imgs = dr_get_content_img($tiedata['neirong']);
        $tupianzu = [];
        foreach ($imgs as $key => $value){
            $tupianzu[] = $value;
        }
        $url = SITE_URL.'uploadfile/"';
        // 这是你要替换成的空字符串  
        $replacement = '';
        $decodedUrl = html_entity_decode($tupianzu[0]);
        // 使用变量和str_replace函数来替换URL中的特定部分  
        $newUrl = str_replace($url, $replacement, $decodedUrl);
        if(dr_count($imgs) > 0){
            if($quantupianlist == 0) {
                $tupian = $newUrl;
            } elseif ($quantupianlist == 2 || $quantupianlist == 3 || $quantupianlist == 4){
                $tupian = $newUrl.'?'.$houzhuitu;
            }
            
        } elseif ($tiedata['jiugetu']) {
            $tupians = dr_string2array($tiedata['jiugetu']);
            //$tupian =$tupian['file'][0];
            $tupian = dr_thumb($tupians['file'][0]);
        } else {
            $tupian = '0';
        }
        $data = [
            'title' => $title,
            'jianjie' => $jianjie,
            'tupian' => $tupian,
            ];
        $this->_json(1, 1, $data);
    }
    
  
   
}
